package com.quatrix.openphantasy.client.datasource;

import com.smartgwt.client.data.OperationBinding;
import com.smartgwt.client.data.RestDataSource;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.DSOperationType;
import com.smartgwt.client.types.DSProtocol;

public class BaseDS extends RestDataSource {

	void _bindOps(String url) {
		
		OperationBinding add = new OperationBinding(DSOperationType.ADD, url);
		OperationBinding fetch = new OperationBinding(DSOperationType.FETCH, url);
		OperationBinding update = new OperationBinding(DSOperationType.UPDATE, url);
		update.setDataProtocol(DSProtocol.GETPARAMS);
		OperationBinding remove = new OperationBinding(DSOperationType.REMOVE, url);
		setOperationBindings(add, fetch, update, remove);	
	}
	
	BaseDS(String id, String url) {
		setID(id);
		setClientOnly(false);
		
		setDataFormat(DSDataFormat.JSON);
		setDataProtocol(DSProtocol.GETPARAMS);
		setJsonRecordXPath("/response/data");

		_bindOps(url);
	}
}
